package com.xy.tool.minio.configuration;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

@Configuration
@EnableConfigurationProperties(MinioProp.class)
public class MinioConfig {

    @Autowired
    private MinioProp minioProp;

    /**
     * 获取MinioClient
     */
    @Bean
    public MinioClient minioClient() {
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioProp.getEndpoint())
                .credentials(minioProp.getAccessKey(), minioProp.getSecretKey())
                .build();
        //设置连接超时时间 ， 写超时时间， 读超时时间
        minioClient.setTimeout(minioProp.getConnectTimeout(), minioProp.getWriteTimeout(), minioProp.getReadTimeout());
        if (Objects.isNull(minioClient)) {
            return null;
        }
        return minioClient;
    }

}
